<template>
  <a-modal
      :title="title"
      :width="800"
      :visible="visible"
      :confirmLoading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭"
  >
    <a-form :form="form">
      <a-form-item label="车道信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-select
            v-decorator="['armId', { rules: [{ required: true, message: '请选择车道信息!' }] }]"
            placeholder="请选择车道信息"
        >
          <a-select-option v-for="(item, index) in armListByMac" :key="index" :value="item.value">{{
              item.name
            }}</a-select-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { deleteAction, getAction, downFile } from '@/api/manage'
export default {
  name: 'inparkinglotCarOutBatch',
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      result: {},
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        getArmListByMac: '/parking/parkArmInfo/parkArmOutInfoList',
        outBatch: '/parking/zombieCar/outBatch', // 参数有两个，1是车道列表的选择的那个id（armId），2是当前滞留车辆的id（id）
      },
      armListByMac: [],
    }
  },
  created() {},
  methods: {
    //   获取下拉框内容
    getArmListByMac() {
      let _self = this
      let params = {}
      params.parkCode = this.result.parkCode
      getAction(this.url.getArmListByMac,params).then((res) => {
        if (+res.code != 0) return
        let armListByMac = [];
        for (let key in res.result) {
          armListByMac.push({ name: res.result[key].armName, value: res.result[key].id })
        }
        _self.armListByMac = armListByMac;
      })
    },
    add() {
      this.batchEdit({})
    },
    batchEdit(record,parkCode) {
      this.result.parkCode = parkCode
      let _self = this
      _self.getArmListByMac()
      this.result.plateNos = record
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          values.plateNos = this.result.plateNos
          that.confirmLoading = true
          let formData = Object.assign(this.model, values)
          //时间格式化
          formData.updateTime = formData.updateTime ? formData.updateTime.format('YYYY-MM-DD HH:mm:ss') : null
          getAction(that.url.outBatch, formData)
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.$emit('ok')
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.confirmLoading = false
                that.close()
              })
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style>
</style>
